package com.example.resp;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "返回结果实体类", description = "结果实体类")
public class ResultVo<T> {

    // 状态码
    private Integer code;
    // 状态信息
    private String msg;
    // 返回对象
    private T data;


    public static <T> ResultVo<T> success(T data) {
        return responseResult(ResultCodeEnum.SUCCESS, data);
    }

    public static <T> ResultVo<T> success(String msg, T data) {
        return responseResult(ResultCodeEnum.SUCCESS.getCode(), msg, data);
    }

    public static <T> ResultVo<T> failure(T data) {
        return responseResult(ResultCodeEnum.FAILURE, data);
    }

    public static <T> ResultVo<T> failure(String msg, T data) {
        return responseResult(ResultCodeEnum.FAILURE.getCode(), msg, data);
    }

    public static <T> ResultVo<T> responseResult(ResultCodeEnum resultCodeEnum, T data) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(resultCodeEnum.getCode());
        result.setMsg(resultCodeEnum.getMsg());
        result.setData(data);
        return result;
    }

    public static <T> ResultVo<T> responseResult(Integer code, String msg, T data) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

}